<template>
  <div class="cost-topology-main">
    <div class="topology-legend">
      <div class="topology-item" v-for="(item, i) in legendList" :key="i">
        <div class="icon" :style="{ background: item.color }"></div>
        <div class="name">{{ item.name }}</div>
      </div>
    </div>
    <div class="topology-chart">
      <div class="topology-chart-right">
        <div class="item-name">{{ name }}</div>
        <div v-for="item in 16" :key="item" style="position: relative">
          <div class="item-line" v-if="item === 1"><div class="line-up"></div></div>
          <div class="item-line" v-if="item >= 2 && item <= 3"><div class="line"></div></div>
          <div class="item-line-bottom" v-if="item === 4"><div class="line-down"></div></div>
          <div class="item-card" v-if="item >= 5 && item <= 8">
            <div class="title">{{ typeList[item - 5].name }}</div>
            <div class="content">
              <span class="value">{{ data[typeList[item - 5].value] ? data[typeList[item - 5].value][0] : 0 }}</span>
              <span class="unit">{{ typeList[item - 5].unit }}</span>
            </div>
          </div>
          <div class="item-line" v-if="item >= 9 && item <= 12"><div class="line line2"></div></div>
          <div class="item-card item-card2" v-if="item >= 13 && item <= 16">
            <div class="title">账单</div>
            <div class="content">
              <span class="value">{{ data[typeList[item - 13].value] ? data[typeList[item - 13].value][1] : 0 }}</span>
              <span class="unit">元</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";

defineProps({
  data: {
    type: Object as any,
    required: false,
    default: () => ({})
  },
  colorList: {
    type: Array,
    required: false,
    default: () => []
  },
  name: {
    type: String,
    required: false,
    default: ""
  },
  typeList: {
    type: Array as any,
    required: false,
    default: () => []
  }
});
const legendList = reactive([
  { name: "计量", color: "#4880FFFF" },
  { name: "计费", color: "#FFC400FF" }
]);
</script>

<style scoped lang="scss">
$line-border: 1px;
$card-height: 56px;
$line-div: 108px;
$line-width: 48px;
.cost-topology-main {
  display: grid;
  grid-template-rows: 50px 1fr;
  width: 100%;
  height: 100%;
  .topology-legend {
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 24px;
    justify-content: end;
    font-size: 14px;
    .topology-item {
      display: grid;
      grid-template-columns: 20px 1fr;
      align-items: center;
      .icon {
        width: 14px;
        height: 14px;
      }
    }
  }
  .topology-chart {
    display: grid;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    .topology-chart-right {
      position: relative;

      // height: 100%;
      display: grid;
      grid-template-rows: repeat(4, $card-height);
      grid-template-columns: $line-div 160px $line-div 160px;
      grid-auto-flow: column;
      gap: 10px;
      justify-content: end;
      width: 650px;
      .item-name {
        position: absolute;
        top: calc(50% - 30px);
        left: 0;
        width: 86px;
        height: 46px;
        font-size: 16px;
        line-height: 46px;
        color: var(--el-bg-color);
        text-align: center;
        background: rgb(94 151 255 / 100%);
        border: 8.38px solid var(--el-bg-color);
        border-radius: 12px;
      }
      .item-line {
        position: absolute;
        top: calc($card-height / 2);
        right: calc(($line-div - $line-width) / 2);
      }
      .item-line-bottom {
        position: absolute;
        right: calc(($line-div - $line-width) / 2);
        bottom: calc($card-height / 2);
      }
      .item-card {
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        padding: 3px 16px;
        background: rgb(89 143 247 / 5%);
        border-left: 4px solid #4880ffff;
        box-shadow: 0 0 4px var(--el-border-color);
        .title {
          font-size: 14px;
          font-weight: 500;
        }
        .content {
          margin-top: 6px;
          .value {
            font-size: 16px;
            font-weight: 700;
            color: #4880ffff;
            letter-spacing: 0;
          }
          .unit {
            margin-left: 8px;
            font-size: 12px;
            font-weight: 400;
            line-height: 20px;
            color: var(--el-header-menu-text-color);
            letter-spacing: 0;
          }
        }
      }
      .item-card2 {
        background: rgb(255 195 0 / 5%);
        border-left: 4px solid #ffc400ff;
        .value {
          font-size: 16px;
          font-weight: 700;
          color: #ffc400ff;
          letter-spacing: 0;
        }
      }
    }
  }
  .line {
    position: relative;
    width: $line-width;
    height: 0;
    border: $line-border solid #4880ffff;
    &::after {
      position: absolute; /* 绝对定位，以便可以相对于 .line 定位 */
      top: 50%; /* 将小方块垂直居中对齐 */
      left: 100%; /* 将小方块放置在 .line 的右侧 */
      width: 6px; /* 小方块的宽度 */
      height: 6px; /* 小方块的高度 */
      content: ""; /* 必须设置 content 属性 */
      background-color: #4880ffff; /* 小方块的背景颜色 */
      transform: translate(-50%, -50%); /* 微调以确保小方块居中对齐 */
      // border-radius: 50%;
    }
  }
  .line2 {
    border: $line-border solid #ffc400ff;
    &::after {
      background-color: #ffc400ff;
    }
  }
  .line-up {
    position: relative;
    width: 86px;
    height: $card-height + 10;
    border: $line-border * 2 solid #4880ffff;
    border-right: 0;
    border-bottom: 0;
    border-radius: 8px 0 0;
    &::after {
      position: absolute; /* 绝对定位，以便可以相对于 .line 定位 */
      top: -1px; /* 将小方块垂直居中对齐 */
      left: 100%; /* 将小方块放置在 .line 的右侧 */
      width: 6px; /* 小方块的宽度 */
      height: 6px; /* 小方块的高度 */
      content: ""; /* 必须设置 content 属性 */
      background-color: #4880ffff; /* 小方块的背景颜色 */
      transform: translate(-50%, -50%); /* 微调以确保小方块居中对齐 */
      // border-radius: 50%;
    }
  }
  .line-down {
    position: relative;
    width: 86px;
    height: $card-height + 10;
    border: $line-border * 2 solid #4880ffff;
    border-top: 0;
    border-right: 0;
    border-radius: 0 0 0 8px;
    &::after {
      position: absolute; /* 绝对定位，以便可以相对于 .line 定位 */
      top: calc(100% + 1px); /* 将小方块垂直居中对齐 */
      left: 100%; /* 将小方块放置在 .line 的右侧 */
      width: 6px; /* 小方块的宽度 */
      height: 6px; /* 小方块的高度 */
      content: ""; /* 必须设置 content 属性 */
      background-color: #4880ffff; /* 小方块的背景颜色 */
      transform: translate(-50%, -50%); /* 微调以确保小方块居中对齐 */
      // border-radius: 50%;
    }
  }
}
</style>
